{extend name='main'}

{block name="button"}
<!--{if auth("index")}-->
<button data-open='{:url("index")}' data-title="通知列表" class='layui-btn layui-btn-sm layui-btn-primary'>通知列表</button>
<!--{/if}-->
{/block}

{block name="content"}
<form onsubmit="return false" data-auto="true" action="{:request()->url()}" method="post" class='layui-form layui-card' autocomplete="off">
    <div class="layui-card-body padding-left-40">
        <div class="layui-form-item">
            <label class="layui-form-label">通知标题</label>
            <div class="layui-input-block">
                <input name="title" value='{$vo.title|default=""}' required placeholder="请输入通知标题" class="layui-input">
            </div>
        </div>
        {if isset($vo) and isset($vo.send_type)}
        {else}
            {php}$sendType = (isset($vo['send_type']) && $vo['send_type'] != '')?$vo['send_type']:0;{/php}
            <div class="layui-form-item">
                <label class="layui-form-label">通知类型</label>
                <div class="layui-input-block">
                    <select name='send_type' class='layui-select' lay-search lay-filter="sendType_filter">
                        {foreach $noticeType as $key=>$type}
                        {eq name='key' value='$vo.send_type|default=0'}
                        <option selected value='{$key}'>{$type}</option>
                        {else}
                        <option value='{$key}'>{$type}</option>
                        {/eq}
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item userselect" id="userselect1" {if $sendType neq 0}style="display:none"{/if}>
            <label class="layui-form-label">会员列表</label>
            <div class="layui-input-block">
                <textarea name="users" placeholder="请输入会员列表" class="layui-textarea">{$vo.users|default=""}</textarea>
                <p>多个会用用(,)来分割</p>
            </div>
        </div>
        <div class="layui-form-item userselect" id="userselect2" {if $sendType neq 1}style="display:none"{/if}>
        <label class="layui-form-label">会员组</label>
        <div class="layui-input-block">
            <select name='user_groupid' class='layui-select' lay-search>
                {foreach $userGroups as $usergroup}
                {eq name='usergroup.id' value='$vo.users|default=0'}
                <option selected value='{$usergroup.id}'>{$usergroup.title}</option>
                {else}
                <option value='{$usergroup.id}'>{$usergroup.title}</option>
                {/eq}
                {/foreach}
            </select>
        </div>
        </div>
        {/if}
        <div class="layui-form-item">
            <label class="layui-form-label">通知内容</label>
            <div class="layui-input-block">
                <textarea name='content'>{$vo.content|default=""}</textarea>
            </div>
        </div>
        {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}
        <div class="hr-line-dashed "></div>
        <div class="layui-form-item text-center">
            <button class="layui-btn" type='submit'>保存数据</button>
            <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
        </div>
    </div>
</form>
{/block}

{block name='script'}
<script>
    require(['ckeditor'], function () {
        var editor;
        setTimeout(function () {
            if (editor) editor.destroy();
            editor = window.createEditor('[name="content"]');
        }, 100);
    });

    layui.use(['layer','jquery', 'form'], function () {
        var layer = layui.layer,
            form = layui.form,
            $ = layui.jquery;

        layui.form.render();

        form.on('select(sendType_filter)', function(data){
            var dataVal = data.value;
            $('.userselect').hide();
            if(dataVal <2){
                $('.userselect:eq('+dataVal+')').show();
            }
        });
    });
</script>
{/block}